package view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.*;

/**
 *
 * @author Sacha MASSON
 */
public class MainFrame extends JFrame implements ActionListener {

    private DefaultListModel l1;
    private DefaultListModel l2;
    private GroupList glist;
    private ContactList clist;
    private ContactDisplay cd;
    private ArrayList al;
    private Menu m;

    public MainFrame(ArrayList a) {
        al = a;
        m = new Menu(al, this);
        this.setJMenuBar(m);
        initComponents();
        this.repaint();

    }

    private void initComponents() {
        cd = new ContactDisplay(al);
        clist = new ContactList(al, cd);
        glist = new GroupList(clist);

        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        GroupLayout layout = new GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                        .addComponent(glist, GroupLayout.PREFERRED_SIZE, 200, GroupLayout.PREFERRED_SIZE)
                        .addComponent(clist, GroupLayout.PREFERRED_SIZE, 200, GroupLayout.PREFERRED_SIZE)
                        .addComponent(cd, GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
                layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                .addComponent(glist)
                .addComponent(clist)
                .addComponent(cd, GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
        );
        cd.setBorder(BorderFactory.createTitledBorder("Informations"));
        glist.setBorder(BorderFactory.createTitledBorder("Groups"));
        clist.setBorder(BorderFactory.createTitledBorder("Contact"));
        pack();
        this.setTitle("AddressBook - Sacha MASSON - SI 3");
        this.setVisible(true);
    }

    @Override
    public void actionPerformed(ActionEvent e) {

    }
}
